package com.itany.controller;

import com.github.pagehelper.PageInfo;
import com.itany.pojo.Permission;
import com.itany.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Author：sl
 * Date：2019-09-25 上午10:41
 * Description：<描述>
 */
@RequestMapping("/permission")
@Controller
public class PermissionController {

    @Autowired
    PermissionService permissionService;

    @RequestMapping("/findAllPermission")
    @ResponseBody
    public Map<String, Object> findAllPermission(@RequestParam(defaultValue = "1") Integer page,
                                                 @RequestParam(defaultValue = "5") Integer rows) {
        Map<String, Object> map = new HashMap<String, Object>();
        PageInfo<Permission> info = permissionService.findAllPermission(page, rows);
        map.put("total", info.getTotal());
        map.put("rows", info.getList());
        return map;
    }


    @RequestMapping("/findModule")
    @ResponseBody
    public List<Permission> findModule() {

        List<Permission> list = permissionService.findModule();
        return list;
    }


    @RequestMapping("/modify")
    public String modify(Permission permission) {
        System.out.println(permission);
        permissionService.modifyById(permission);
        return "/backend/permission";
    }
}
